package com.kang.controller.feign;

import com.kang.entity.Park;
import com.kang.feign.UserFeignClient;
import com.kang.util.WebResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 康康
 * @Date: 2023/03/12/11:10
 */
@RestController
@Api(tags = "园区调用")
@RequestMapping("/admin/park")
@Slf4j
public class ParkFeign {

    @Autowired
    private UserFeignClient parkFeignClient;


    @ApiOperation("分页获取园区")
    @GetMapping("getParkPage")
    public WebResponse getParkPage(Integer pageNum, Integer pageSize, String parkName,String startTime,String endTime,Integer status) {
        try {
            return WebResponse.resSuccess("分页查询社区成功",parkFeignClient.getParkPage(pageNum,pageSize,parkName,startTime,endTime,status));
        } catch (Exception ex) {
            log.error("分页查询社区失败",ex);
            return WebResponse.resFail("分页查询社区失败",null);
        }
    }

    @ApiOperation("查询社区详情")
    @GetMapping("getParkById")
    public WebResponse getParkById(Integer id) {
        try {
            return WebResponse.resSuccess("查询社区详情成功",parkFeignClient.getParkById(id));
        } catch (Exception ex) {
            log.error("查询社区详情失败",ex);
            return WebResponse.resFail("查询社区详情失败",null);
        }
    }

    @ApiOperation("删除社区")
    @PostMapping("deletePark")
    public WebResponse deletePark(@RequestBody Park park) {
        try {
            return WebResponse.resSuccess("删除社区成功",parkFeignClient.deletePark(park));
        } catch (Exception ex) {
            log.error("删除社区失败",ex);
            return WebResponse.resFail("删除社区失败",null);
        }
    }

}
